<?php 

class paomeCenterController extends base
{
    public function __construct()
    {
        parent::__construct('show');
        $this->printResult = TRUE;
        $this->in_user();
    }

    /**
    * 个人中心--获取用户信息
    */
    public function dogetUserInfo()
    {
        // 获取传入参数
        $uid = common::request('uid', 'R');
    	empty($uid) && $uid = $this->uid;
    	if(empty($uid))
        {
          $_ENV['error']->getErrors(201);
          exit;
        }
        $userInfo = $this->redis->hgetall(REDIS_PREFIX . 'UserInfo_' . $uid);
        $userInfoNew = array();
        $userInfoNew['uid'] = $uid;
        $userInfoNew['nickname'] = $userInfo['nickname'];
        $userInfoNew['header'] = $userInfo['header'];
        $userInfoNew['gender'] = $userInfo['gender'];

        //计算跑龄
        $runTime = round((time() - $userInfo['addtime']) / 3600);
        $runTime < 24 && $runTime = 24;
        $runDay = round($runTime / 24);
        $runMonth = round($runDay / 30);
        $runDay = $runDay % 30;
        $userInfoNew['run_age'] = "{$runMonth}月{$runDay}天";
        $userInfoNew['addtime'] = date('Y-m-d', $userInfo['addtime']);

        //查看比赛是否开始
        $season = $this->load('paome/paomeHall')->getCurrentSeason();
        $centerInfo = array();
        $centerInfo['isBegin'] = 0;   //是否开始(预选赛)
        $centerInfo['isJoin'] = 0;    //是否参与
        $centerInfo['clubStatus'] = 0; //俱乐部状态
        $clubRankData = array();      //俱乐部排名相关信息
        $userData = array();          //个人跑量数据
        //centerInfo中默认数据
        $centerInfo['mileage'] = '';  //个人累计跑量
        $centerInfo['speed'] = '';  //个人平均配速
        $centerInfo['support_num'] = '';  //累计人气
        $centerInfo['max_mileage'] = '';  //单次最远距离
        $centerInfo['max_mileage_diff'] = '';  //单次最远距离与名人堂最后一名的差
        $centerInfo['mileage_compare'] = '';   //俱乐部的跑量对比昨日升降的幅度
        $centerInfo['club_mileage'] = '';  //战队跑量
        $centerInfo['club_mileage_rank'] = '';  //战队跑量排名
        $centerInfo['club_speed'] = '';  //战队平均配速
        $centerInfo['club_speed_rank'] = '';  //战队平均配速排名
        $centerInfo['is_speed_rise'] = '';  //个人配速对排行榜的影响(1:大于;2:小于)
        $centerInfo['club_speed_compare'] = '';  //战队配速对比昨日升降的幅度
        $centerInfo['club_supporters'] = '';  //战队人气
        $centerInfo['club_supporters_rank'] = '';  //战队人气排名
        $centerInfo['club_support_compare'] = ''; //战队人昨日排名
        $centerInfo['support_diff'] = '';  //个人入驻人气榜的差值
        $centerInfo['user_mileage_rank'] = '';  //个人跑量排名
        $centerInfo['user_count'] = '';  //需要排名的总人数
        $centerInfo['club_count'] = '';  //需要排名的战队数
        $centerInfo['round'] = '';
        $centerInfo['isCertificate'] = '';    

        if($season){
            if($season['start_time'] < time() && $season['end_time'] > time()){
                $centerInfo['isBegin'] = 1;
            }
            if(time() > $season['end_time']){
                $centerInfo['isBegin'] = 2;
            }
            if($season['start_time'] > time() && $season['sign_time'] < time()){
                $centerInfo['clubStatus'] = 1;  //招募期
            }

            //获取当前比赛轮次
            $round = $this->load('paome/paomeHall')->getCurrentRound();

            // 是否加入或创建过俱乐部
            $isInClub = FALSE;
            $isJoinClub = FALSE;
            $isCreateClub = $this->load('paome/paomeClub')->isCreateClubForUid($uid);
            !$isCreateClub && $isJoinClub = $this->load('paome/paomeClub')->getUserCurrentClubInfo($uid, 'id');
            ($isCreateClub || $isJoinClub) && $isInClub = TRUE;
            $isInClub && $centerInfo['isJoin'] = 1;

            //获取俱乐部
            $clubInfo = $this->load("paome/paomeHall")->getClubByUid($uid);
            if(!empty($clubInfo)){
                $centerInfo['isJoin'] = 1;
                $userInfoNew['club_name'] = $clubInfo['title'];
                $userInfoNew['club_id'] = $clubInfo['id'];
                $userInfoNew['club_image'] = $clubInfo['image'];
                //是否为团长
                $userInfoNew['is_leader'] = 0;
                if($userInfo['uid'] == $clubInfo['head_uid']){
                    $userInfoNew['is_leader'] = 1;
                }

                //获取俱乐部排名和数据
                if($round == 100){
                    $clubRankData = $this->load('paome/center')->getClubRankInZb($clubInfo['id'], $season);
                }else{
                    $clubRankData = $this->load('paome/center')->getCurrentClubRank($clubInfo['id'], $season);
                }
                //查看俱乐部当前状态
                $clubStatus = $this->load('paome/center')->getClubStatus($season['id'], $clubInfo['id']);
                if($clubStatus){
                    if($clubStatus['status'] == 5 || $clubStatus['status'] == 10){
                        $centerInfo['clubStatus'] = 2;    //已淘汰
                    }
                    if($clubStatus['status'] == 20){
                        $centerInfo['clubStatus'] = 3;    //已结束
                    }
                }  
                //判断是否显示证书
                $centerInfo['isCertificate'] = $this->load('paome/center')->isCertificate($season['id'], $clubInfo['id']);
            }

            //获取个人跑步数据
            $userData = $this->load('paome/center')->getUserData($uid, null);
            if($userData){
                empty($clubInfo) && $centerInfo['isJoin'] = 2;  //参加过
                $centerInfo['mileage'] = $userData['mileage'];   //累计跑量
                $centerInfo['speed'] = $userData['speed'];    //平均配速
                $centerInfo['support_num'] = $userData['support_num'];   //人气
                $centerInfo['max_mileage'] = $userData['max_mileage'];   //单次最远距离
                //争霸赛期间
                if($round == 100){
                    $date = date('Ymd');
                    if($season['end_time'] < time()){
                        $date = date('Ymd', $season['end_time']);
                    }
                    $speedArr = $this->load('paome/cup')->getUserCurrentDayMileage($season['id'], $clubInfo['id'], $uid, $date);
                    $centerInfo['speed'] = $this->load('paome/cup')->getSecSpeed($speedArr[0], $speedArr[1]);
                    $centerInfo['speed'] = common::sec3format($centerInfo['speed']);
                    $centerInfo['max_mileage'] = $this->load('paome/center')->maxMileageByDay($uid, $date);
                }
                
                //获取最远榜
                $maxMileage = $this->load('paome/paomeHall')->getHallOfFameList('max_mileage');
                if(!empty($maxMileage) && $round != 100){
                    foreach ($maxMileage as $k => $v) {
                        if($k == count($maxMileage) - 1){
                            //入驻最远距离名人堂的差距
                            $centerInfo['max_mileage_diff'] = $v['max_mileage'] - $centerInfo['max_mileage'];
                        }
                    }
                }
            }

            $centerInfo['round'] = $round;
            if(!empty($round)){
                $mileage_compare = $this->load('paome/rank')->getObjectRankChange($season['id'], $round, $uid, 15);
                //正负值判断上升或下降
                if(!empty($mileage_compare)){
                    $centerInfo['mileage_compare'] = $mileage_compare['num'];
                }               
            }

            if($clubRankData){
                if(!empty($clubRankData['club_mileage']) && !empty($centerInfo['mileage'])){
                    $centerInfo['club_mileage'] = $clubRankData['club_mileage'];   //总里程
                    $centerInfo['club_mileage_rank'] = $clubRankData['club_mileage_rank'];   
                }
                if(!empty($clubRankData['club_speed']) && !empty($centerInfo['speed'])){
                    $centerInfo['club_speed'] = $clubRankData['club_speed'];   //平均配速
                    $centerInfo['club_speed_rank'] = $clubRankData['club_speed_rank'];;   
                    //个人对排行榜的影响
                    if(!empty($centerInfo['speed']) && $centerInfo['speed'] <= $centerInfo['club_speed']){                      
                        $centerInfo['is_speed_rise'] = 1;    //大于
                    }elseif (!empty($centerInfo['speed']) && $centerInfo['speed'] > $centerInfo['club_speed']) {
                        $centerInfo['is_speed_rise'] = 2;    //小于
                    }
                    $speed_compare = $this->load('paome/rank')->getObjectRankChange($season['id'], $round, $clubInfo['id'], 5);
                    if($speed_compare){
                        $centerInfo['club_speed_compare'] = $speed_compare['num'] ? $speed_compare['num'] : '';
                    }
                }
                if(!empty($clubRankData['club_supporters']) && !empty($centerInfo['support_num'])){
                    $centerInfo['club_supporters'] = $clubRankData['club_supporters'];   //人气
                    $centerInfo['club_supporters_rank'] = $clubRankData['club_supporters_rank']; 
                    if(!empty($centerInfo['support_num'])){
                        $support_compare = $this->load('paome/rank')->getObjectRankChange($season['id'], $round, $clubInfo['id'], 10);
                        if($support_compare){
                            $centerInfo['club_support_compare'] = $centerInfo['club_supporters_rank'] - $support_compare['num'];
                        }
                        //获取人气榜
                        $support = $this->load('paome/paomeHall')->getHallOfFameList('support_num');
                        if(!empty($support)){
                            foreach ($support as $k => $v) {
                                if($k == count($support) - 1){
                                    $centerInfo['support_diff'] = $v['support_num'] - $centerInfo['support_num'];
                                }
                            }
                        }
                    }  
                }
            }
            //获取个人排名(跑量榜)
            $userRank = $this->load('paome/center')->getCurrentUserRank($uid, $season);
            if(!empty($userRank) && !empty($centerInfo['mileage'])){
                $centerInfo['user_mileage_rank'] = $userRank['user_mileage_rank'];  //个人跑量排名
            }

            //获取需要排名的用户总数
            $userCount = $this->load('paome/center')->getUserCount($season);
            $centerInfo['user_count'] = $userCount;

            //获取需要排名的俱乐部总数
            $clubCount = $this->load('paome/center')->getClubCount($season);
            $centerInfo['club_count'] = $clubCount;
        }
        $wxUrl = "http://".$this->config['host']."/paome_webIndex/paoshare";
        $shareTitle = "我正在参与跑么杯争霸赛，快来加入我的战队赢取5000元奖励吧！";
        $description = "11月14日，就在虎扑跑步";
        if($centerInfo['isJoin'] == 1){
            //$wxUrl = $this->load('paome/share')->pubOpenIdUrl($uid);
            $wxUrl = "http://".$this->config['host']."/paome_share/shareLink?target_uid=".$uid;
            $shareTitle = "我正在参与跑么杯争霸赛，需要你的助力！助力即可抽奖！";
            $description = "每人每天可抽奖三次，最高可赢得iPhone7";
        }
        $this->result['result']['wxUrl'] = $wxUrl;
        $this->result['result']['shareTitle'] = $shareTitle;
        $this->result['result']['description'] = $description;
        $this->result['result']['userInfo'] = $userInfoNew;
        $this->result['result']['centerInfo'] = $centerInfo;
    }

    /**
    * 个人中心--赛季记录
    */
    public function docontestRecord() {
        $uid = $this->uid;
        if(empty($uid))
        {
          $_ENV['error']->getErrors(201);
          exit;
        }
        //第一轮数据
        $userData1 = $this->load('paome/center')->getDataByRound($uid, 1);
        //第二轮数据
        $userData2 = $this->load('paome/center')->getDataByRound($uid, 5);
        //第三轮数据
        $userData3 = $this->load('paome/center')->getDataByRound($uid, 10);
        //争霸赛数据
        $userData4 = $this->load('paome/center')->getDataByRound($uid, 100);
        //当前轮
        $currentRound = $this->load("paome/paomeHall")->getCurrentRound();
        $currentRound == 5 && $currentRound = 2;
        $currentRound == 10 && $currentRound = 3;
        $currentRound == 100 && $currentRound = 4;
        //当前轮的状态
        $roundStatus = 0;   //已结束
        $season = $this->load("paome/paomeHall")->getCurrentSeason();
        if($season){
            if(in_array($season['status'], array(5,6,10,15,16,20,25,26,30,105))){
                $roundStatus = 1;   //进行中
            }
        }

        $this->result['result']['roundStatus'] = $roundStatus;
        $this->result['result']['userData']['userData1'] = $userData1;
        $this->result['result']['userData']['userData2'] = $userData2;
        $this->result['result']['userData']['userData3'] = $userData3;
        $this->result['result']['userData']['userData4'] = $userData4;
        $this->result['result']['currentRound'] = $currentRound;
    }

    /**
    * 个人中心--支持者列表
    */
    public function douserSupportList() {
        $uid = $this->uid;
        if(empty($uid))
        {
          $_ENV['error']->getErrors(201);
          exit;
        }
        
        //正能量列表
        $energyList = $this->load('paome/center')->supportList($uid, 1);
        $energyInfo = array();
        if($energyList){
            foreach ($energyList as $key => $val) {
                $energyInfo[$key]['uid'] = $val['uid'];
                $energyInfo[$key]['energy'] = $val['total_energy'];
                $energyInfo[$key]['nickname'] = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'], 'nickname');
                $energyInfo[$key]['header'] = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'], 'header');
            }
        }

        //点赞列表
        $lightList = $this->load('paome/center')->supportList($uid, 2);
        $lightInfo = array();
        if($lightList){
            foreach ($lightList as $key => $val) {
                $lightInfo[$key]['light'] = $val['total_light'];
                if($val['is_share'] == 0){   //app内
                    $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'], 'nickname');
                    $header = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'], 'header');
                    $lightInfo[$key]['nickname'] = $nickname ? $nickname : 'pm'.time();
                    $lightInfo[$key]['header'] = $header ? $header : 'http://irun.hupu.com/static/images/4.jpg';
                }else{  //微信中
                    $lightInfo[$key]['nickname'] = $val['user_name'] ? $val['user_name'] : 'wx'.time();
                    $lightInfo[$key]['header'] = $val['user_header'] ? $val['user_header'] : 'http://irun.hupu.com/static/images/4.jpg';
                }
            }
        }
        
        $this->result['result']['energyInfo'] = $energyInfo;
        $this->result['result']['lightInfo'] = $lightInfo;
    }

    /**
    * 个人中心--个人公告
    */
    public function douserAffiche() {
        $uid = $this->uid;
        if(empty($uid))
        {
          $_ENV['error']->getErrors(201);
          exit;
        }
        //查看比赛是否开始
        $season = $this->load('paome/paomeHall')->getCurrentSeason();
        $content = '竞赛开始喽，做好备战计划进击跑量榜，配速榜和人气榜夺得三冠王吧！';
        if(!empty($season)){
            $userCount = $this->load('paome/paomeHall')->getNeedRankUser();
            $index = $this->redis->get(REDIS_PREFIX . 'UserCenterIndex' .$uid);
            empty($index) && $index = 1;
            if($index == 1){
                //全员跑量key
                $rankUserKeyMile = 'rankUser-mileage-'.$season['id'].'-'.$season['status'];
                //全员跑量榜前十
                $userMileage = $this->redis->zRange($rankUserKeyMile,0,9);
                if($userMileage && in_array($uid, array_values($userMileage))){
                    $rank = ($this->redis->zRevRank($rankUserKeyMile,$uid) !==false) ? ($this->redis->zRevRank($rankUserKeyMile,$uid)+1) :'';
                    !empty($rank) && $content = "您的累计跑量在全员跑量榜上排名前".$rank."继续加油吧！";
                }
                $index++;
            }elseif($index == 2){
                //单次最远距离前十
                $maxMileage = $this->load('paome/paomeHall')->getHallOfFameList('max_mileage');
                $arrUid = array();
                if(!empty($maxMileage)){
                    $i = 1;
                    foreach ($maxMileage as &$v) {
                        $arrUid[$i] = $v['uid'];
                        $i++;
                    }
                }
                if($arrUid && in_array($uid, $arrUid)){
                    $rank = 0;
                    foreach ($arrUid as $key => $val) {
                        if($arrUid == $val){
                            $rank = $key;
                        }
                    }
                    if($userCount && $rank){
                        $content = "恭喜您入驻名人堂获封“单次最远跑神”封号。最远距离排名".$rank."/".$userCount;
                    }
                }
                $index++;
            }elseif($index == 3){
                //累计人气排名前10
                $supports = $this->load('paome/paomeHall')->getHallOfFameList('support_num');
                $arrUid = array();
                if(!empty($supports)){
                    $i = 1;
                    foreach ($supports as &$v) {
                        $arrUid[$i] = $v['uid'];
                        $i++;
                    }
                }
                if($arrUid && in_array($uid, $arrUid)){
                    $rank = 0;
                    foreach ($arrUid as $key => $val) {
                        if($arrUid == $val){
                            $rank = $key;
                        }
                    }
                    if($userCount && $rank){
                        $content = "恭喜您入驻名人堂获封“人气王”封号。人气排名".$rank."/".$userCount;
                    }
                }
                $index++;
            }elseif($index == 4){
                //配速排名前10
                $speed = $this->load('paome/paomeHall')->getHallOfFameList('speed', 'ASC');
                $arrUid = array();
                if(!empty($speed)){
                    $i = 1;
                    foreach ($speed as &$v) {
                        $arrUid[$i] = $v['uid'];
                        $i++;
                    }
                }
                if($arrUid && in_array($uid, $arrUid)){
                    $rank = 0;
                    foreach ($arrUid as $key => $val) {
                        if($arrUid == $val){
                            $rank = $key;
                        }
                    }
                    if($userCount && $rank){
                        $content = "恭喜您入驻名人堂获封“配速王”封号。配速排名".$rank."/".$userCount;
                    }
                }
                $index++;
            }
            if($index == 5 || empty($content)){
                $content = $this->doclubAffiche($uid);
                $index = 1;
            }
            $this->redis->set(REDIS_PREFIX . 'UserCenterIndex' .$uid, $index);
            if(in_array($season['status'], array(106, 120))){
                $content = $this->doclubAffiche($uid);
            }
        }

        $this->result['result']['content'] = $content;
    }

    /**
    * 俱乐部公告
    */
    public function doclubAffiche($uid = null) {
        $clubId = common::request('clubId', 'R');
        if(empty($clubId) && empty($uid)){
            $_ENV['error']->getErrors(101);
            exit;
        }
        if($clubId){
            $clubInfo = $this->load("paome/paomeClub")->getClubInfo($clubId);
        }
        if($uid){
            $clubInfo = $this->load("paome/paomeHall")->getClubByUid($uid);
        }
        //获取当前赛季状态
        $season = $this->load('paome/paomeHall')->getCurrentSeason();
        $round = $this->load("paome/paomeHall")->getPhaseByTime(time(), time());
        
        $affiche = array();
        $affiche['content'] = '竞赛开始喽，做好备战计划进击跑量榜，配速榜和人气榜夺得三冠王吧！';
        if(!empty($round) && !empty($clubInfo)){
            $clubStatus = $this->load('paome/center')->getClubStatus($round['contest_id'], $clubInfo['id']);    //俱乐部状态
            empty($clubStatus) && $clubStatus['status'] = '';
            $statusDict = array(
                1 => '第一轮预选赛',
                5 => '第一轮决赛',
                10 => '第二轮预选赛',
                15 => '第二轮决赛',
                20 => '第三轮预选赛',
                25 => '第三轮决赛',
                100 => '争霸赛'
            );
            if($round['type'] == 1){     //招募期
                $index = $this->redis->get(REDIS_PREFIX . 'ClubRecruitIndex' .$clubInfo['id']);
                empty($index) && $index = 1;
                if($index == 1){
                    if($clubInfo['user_num'] < 5){
                        $diffNum = 5 - $clubInfo['user_num'];
                        $affiche['content'] = "俱乐部已招募".$clubInfo['user_num']."人，还需要招".$diffNum."人，快快去召集好友吧！否则可是会失去竞赛资格的哦！";
                    }elseif($clubInfo['user_num'] > 5 && $clubInfo['user_num'] < 30){
                        $diffNum = 30 - $clubInfo['user_num'];
                        $affiche['content'] = "俱乐部已招募".$clubInfo['user_num']."人，还可以招".$diffNum."人，与队友协商作战计划做好赛前准备";
                    }elseif($clubInfo['user_num'] == 30){
                        $affiche['content'] = "俱乐部已招募30人，与队友协商作战计划做好赛前准备";
                    }
                    $index++;
                }elseif($index == 2){
                    $diffTime = $round['end_time'] - time();
                    $diffTime = ceil($diffTime/86400);
                    if($diffTime > 0){
                        $affiche['content'] = "预选赛还有".$diffTime."天就可以了，摆好奔跑姿势吧！";
                    }
                    $index = 1;
                }
                $this->redis->set(REDIS_PREFIX . 'ClubRecruitIndex' .$clubInfo['id'], $index);
            }elseif(in_array($round['type'], array(5, 15, 25))){   //预选赛
                $index = $this->redis->get(REDIS_PREFIX . 'ClubGameIndex' .$clubInfo['id']);
                empty($index) && $index = 1;
                if($index == 1){
                    if($round['type'] == 5 && $clubStatus['status'] == 5){
                        $affiche['content'] = "诶呀！俱乐部没有满足5人不能参与第一轮竞赛哦！别伤心，继续召集成员参与第二轮竞赛吧！";
                    }
                    $index++;
                }elseif($index == 2){
                    //获取俱乐部数据
                    $clubData = $this->load('paome/center')->getClubData($clubInfo['id']);
                    if(empty($clubData)){
                        $affiche['content'] = "哇，竞赛好激烈！已经有战队在争夺排行榜榜首了，我们的战队也不能落后快快奔跑！";
                    }
                    $index++;
                }elseif($index == 3){
                    $maxMileage = $this->load('paome/center')->getMaxDataClub($clubInfo['id'], date('Ymd'), 'max_mileage');
                    if(!empty($maxMileage) && !empty($maxMileage['max_mileage'])){
                        $affiche['content'] = "太棒了！".$maxMileage['nickname']."给团队贡献了".$maxMileage['max_mileage']."km，团长要好好奖励Ta啊";
                    }
                    $index++;
                }elseif($index == 4){
                    $maxSpeed = $this->load('paome/center')->getMaxDataClub($clubInfo['id'], date('Ymd'), 'speed', 'asc');
                    if(!empty($maxSpeed) && !empty($maxSpeed['speed'])){
                        $affiche['content'] = "太棒了！".$maxSpeed['nickname']."的最快配速到达了".$maxSpeed['speed']."，战队的平均配速提升喽！团长要好好奖励Ta啊";
                    }
                    $index++;
                }elseif($index == 5){
                    $maxSupport = $this->load('paome/center')->getMaxDataClub($clubInfo['id'], date('Ymd'), 'support_num');
                    if(!empty($maxSupport) && !empty($maxSupport['support_num'])){
                        $affiche['content'] = "太棒了！".$maxSupport['nickname']."获得".$maxSupport['support_num']."个人气，战队的人气榜排名提升喽！团长要好好奖励Ta啊！";
                    }
                    $index++;
                }elseif($index == 6){
                    $diff = $round['end_time'] - time();
                    if(ceil($diff/86400) == 1){
                        $affiche['content'] = "预选赛今天22：00就要结束了！做好冲刺准备了么！还有前往表忘记在结束前上传自己的成绩不然不会被统计哦！";
                    }
                    $index = 1;
                }
                if(in_array($clubStatus['status'], array(5, 10))){
                    $roundName = $statusDict[$clubStatus['type']];
                    $affiche['content'] = "诶呀！您的战队在".$roundName."中没有晋级！o(>﹏<)o千万别灰心！";
                }
                $this->redis->set(REDIS_PREFIX . 'ClubGameIndex' .$clubInfo['id'], $index);
            }elseif(in_array($round['type'], array(10, 20, 30))){   //冠军赛
                $index = $this->redis->get(REDIS_PREFIX . 'ClubChampionshipIndex' .$clubInfo['id']);
                empty($index) && $index = 1;
                if($index == 1){
                    if($clubStatus['status'] == 15){
                        $affiche['content'] = "战队晋级到到了冠军赛！竞赛更激烈喽！大家要加油哦！";
                    }
                    $index++;
                }elseif($index == 2){
                    //获取俱乐部数据
                    $clubData = $this->load('paome/center')->getClubData($clubInfo['id']);
                    if(empty($clubData)){
                        $affiche['content'] = "哇，竞赛好激烈！已经有战队在争夺排行榜榜首了，我们的战队也不能落后快快奔跑！";
                    }
                    $index++;
                }elseif($index == 3){
                    $maxMileage = $this->load('paome/center')->getMaxDataClub($clubInfo['id'], date('Ymd'), 'max_mileage');
                    if(!empty($maxMileage) && !empty($maxMileage['max_mileage'])){
                        $affiche['content'] = "太棒了！".$maxMileage['nickname']."给团队贡献了".$maxMileage['max_mileage']."km，团长要好好奖励Ta啊";
                    }
                    $index++;
                }elseif($index == 4){
                    $maxSpeed = $this->load('paome/center')->getMaxDataClub($clubInfo['id'], date('Ymd'), 'speed', 'asc');
                    if(!empty($maxSpeed) && !empty($maxSpeed['speed'])){
                        $affiche['content'] = "太棒了！".$maxSpeed['nickname']."的最快配速到达了".$maxSpeed['speed']."，战队的平均配速提升喽！团长要好好奖励Ta啊";
                    }
                    $index++;
                }elseif($index == 5){
                    $maxSupport = $this->load('paome/center')->getMaxDataClub($clubInfo['id'], date('Ymd'), 'support_num');
                    if(!empty($maxSupport) && !empty($maxSupport['support_num'])){
                        $affiche['content'] = "太棒了！".$maxSupport['nickname']."获得".$maxSupport['support_num']."个人气，战队的人气榜排名提升喽！团长要好好奖励Ta啊！";
                    }
                    $index++;
                }elseif($index == 6){
                    $diff = $round['end_time'] - time();
                    if(ceil($diff/86400) == 1){
                        $affiche['content'] = "冠军赛今天22：00就要结束了！做好冲刺准备了么！还有前往表忘记在结束前上传自己的成绩不然不会被统计哦！";
                    }
                    $index++;
                }
                if(in_array($clubStatus['status'], array(5, 10))){
                    $roundName = $statusDict[$clubStatus['type']];
                    $affiche['content'] = "诶呀！您的战队在".$roundName."中没有晋级！o(>﹏<)o千万别灰心！";
                }
                if($index == 7 || empty($affiche['content'])){
                    $affiche['content'] = "冠军赛结束时在跑量榜排名前10名就可以获得总决赛的直通卡哦！大家努力！";
                    $index = 1;
                }
                $this->redis->set(REDIS_PREFIX . 'ClubChampionshipIndex' .$clubInfo['id'], $index);
            }elseif(in_array($round['type'], array(31, 32))){     //冠军赛至争霸赛空挡
                if(empty($clubStatus) && $clubStatus['status'] == 15){
                    $affiche['content'] = "太棒了！您的战队获得了总决赛冠军争霸赛的资格！别傲娇哦！更激烈的争霸赛来了！";
                }else{
                    $affiche['content'] = "诶呀！您的战队在没有晋级！o(>﹏<)o千万别灰心！加入到拥有争霸赛资格的队伍继续参赛吧";
                }
            }elseif($round['type'] == 105){     //争霸赛
                $index = $this->redis->get(REDIS_PREFIX . 'ClubChampionsIndex' .$clubInfo['id']);
                empty($index) && $index = 1;
                if($index == 1){
                    //获取俱乐部数据
                    $clubData = $this->load('paome/center')->getClubData($clubInfo['id']);
                    if(empty($clubData)){
                        $affiche['content'] = "哇，竞赛好激烈！已经有战队在争夺排行榜榜首了，我们的战队也不能落后快快奔跑！";
                    }
                    $index++;
                }elseif($index == 2){
                    $maxMileage = $this->load('paome/center')->getMaxDataClub($clubInfo['id'], date('Ymd'), 'max_mileage');
                    if(!empty($maxMileage) && !empty($maxMileage['max_mileage'])){
                        $affiche['content'] = "太棒了！".$maxMileage['nickname']."给团队贡献了".$maxMileage['max_mileage']."km，团长要好好奖励Ta啊";
                    }
                    $index++;
                }elseif($index == 3){
                    $maxSpeed = $this->load('paome/center')->getMaxDataClub($clubInfo['id'], date('Ymd'), 'speed', 'asc');
                    if(!empty($maxSpeed) && !empty($maxSpeed['speed'])){
                        $affiche['content'] = "太棒了！".$maxSpeed['nickname']."的最快配速到达了".$maxSpeed['speed']."，战队的平均配速提升喽！团长要好好奖励Ta啊";
                    }
                    $index++;
                }elseif($index == 4){
                    $maxSupport = $this->load('paome/center')->getMaxDataClub($clubInfo['id'], date('Ymd'), 'support_num');
                    if(!empty($maxSupport) && !empty($maxSupport['support_num'])){
                        $affiche['content'] = "太棒了！".$maxSupport['nickname']."获得".$maxSupport['support_num']."个人气，战队的人气榜排名提升喽！团长要好好奖励Ta啊！";
                    }
                    $index++;
                }elseif($index == 5){
                    $diff = $round['end_time'] - time();
                    if(ceil($diff/86400) == 1){
                        $affiche['content'] = "争霸赛今天24:00就要结束了！做好冲刺准备了么！还有前往表忘记在结束前上传自己的成绩不然不会被统计哦！";
                    }
                    $index++;
                }
                if($index == 6 || empty($affiche['content'])){
                    $affiche['content'] = "总决赛冠军争霸赛开始啦！跑量榜、配速榜、人气榜三榜都是战队的荣誉，体现战队的协同能力！与小伙伴协商进击其中一个榜单一定会取得好成绩的！";
                    $index == 1;
                }
                $this->redis->set(REDIS_PREFIX . 'ClubChampionsIndex' .$clubInfo['id'], $index);
            }elseif($round['type'] == 106){     //争霸赛空档期
                $affiche['content'] = "争霸赛今日24:00点结束，请各位参赛者在结束前上传自己的成绩不然成绩不做统计哦！";
            }
            in_array($round['type'], array(5, 15, 25)) && $gameRound = 2;
            in_array($round['type'], array(10, 20, 30)) && $gameRound = 4;
            in_array($round['type'], array(31, 32)) && $gameRound = 5;
            $round['type'] == 1 && $gameRound = 1;
            $round['type'] == 105 && $gameRound = 6;
            $round['type'] == 105 && $gameRound = 7;
            if(!empty($gameRound)){
                //获取公告
                $clubId = $clubInfo['id'] ? $clubInfo['id'] : 0;
                $hallAffiche = $this->load('paome/home')->getAffiche($round['contest_id'], $gameRound, $affiche['content'], 2, $clubId);
                if(empty($hallAffiche)){
                    $affiche['add_time'] = time();
                    $affiche['contest_id'] = $round['contest_id'];
                    $affiche['rounds'] = $gameRound;
                    $affiche['type'] = 2;
                    $affiche['club_id'] = $clubId;
                    $this->db->insertRowTable('r_pm_affiche', $affiche);
                }
            }
        }
        if($season['status'] == 120 && !empty($clubInfo)){
            //获取战队积分排名
            $sql = "select score_rank_num from r_pm_score where contest_id = {$season['id']} and club_id = {$clubInfo['id']} and type = 100";
            $rank = $this->db->getOne($sql);
            if($rank == 1){
                $affiche['content'] = "太棒了！战队获得了积分榜冠军！获得了5000元大礼包和奖牌、奖杯、证书、电子勋章！";
            }elseif($rank >= 2 && $rank <= 5){
                $affiche['content'] = "太棒了！战队获得了积分榜第".$rank."名，获得了1000元大礼包和奖牌、证书、电子勋章！";
            }elseif($rank >= 6 && $rank <= 10){
                $affiche['content'] = "太棒了！战队获得了积分榜第".$rank."名，获得了500元大礼包和奖牌、证书、电子勋章！";
            }else{
                $affiche['content'] = "诶呀呀！战队在本赛季获得了奖牌、证书、电子勋章！";
            }
        }
        if($uid){
            return $affiche['content'];
        }else{
            $this->result['result']['content'] = $affiche['content'];
        }
    }

    /**
     * 跑么杯俱乐部公告列表
     * @return [type] [description]
     */
    public function doclubAfficheList(){
        $p = common::request('p', 'R', 1);   //页码
        $clubId = common::request('clubId', 'R');   //俱乐部id
        if(!$clubId){
            $_ENV['error']->getErrors(101);
            exit;
        }
        $countSql = "select count(1) from r_pm_affiche where is_show = 1 and type = 2 and club_id = {$clubId}";
        $offset = 20;
        $num = $this->db->getOne($countSql);

        //分页
        require FILE . 'lib/page.class.php';
        $page = new Page($num, $offset);
        $pageStr = $page->show();
        $start = ($p - 1) * $offset;

        $list = $this->db->getAll("select * from r_pm_affiche where is_show = 1 and type = 2 and club_id = {$clubId} order by add_time desc limit $start,$offset");
        if($list){
            foreach ($list as &$v) {
                $diffTime = time() - $v['add_time'];
                if($diffTime <= 604800){
                    $v['add_time'] = common::timediff($diffTime, 'paome');
                }else{
                    if(date('Y', $v['add_time']) == date('Y')){
                        $v['add_time'] = date('m-d H:i');
                    }else{
                        $v['add_time'] = date('Y-m-d H:i');
                    }
                }
            }
        }
        $this->result['result']['list'] = $list;
    }

}